﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using PccCommonForC;
using System.Xml;
using System.Text;
using System.IO;
using System.Web.UI.HtmlControls;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
using System.Text.RegularExpressions;
using bs_ShowRoom;
using System.Configuration;
using System.Collections;
using System.Security.Cryptography;
using System.Net.Mail;

namespace ShowRoom.admin
{
    public partial class ResetPass : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            string user_id = Session["user_id"].ToString().Trim();
            string password_c = txtPassCurr.Text.ToString().Trim();
            string password = txtPass.Text.ToString().Trim();
            string Type = "0";
            string ok = SaveData(user_id, password_c, password, Type);
            if (ok == "N")
            {
                string Mes = "Cập nhật thành công !";
                string url = "admin.aspx";
                // Response.Write("<script>alert('Quý khách đã đăng ký thành công tài khoản tại showroommypham.com !');window.location='login.aspx?&name=" + txtuser.Text.ToString().Trim() + "'</script>");
                ScriptFunction.ShowMsgTranOpennerUrl_ScriptManager(Mes, Page, url);
            }
            else
            {
                Response.Write("<script>alert('Đả có lỗi xãy ra trong quá trình đăng ký !')</script>");
                return;
            } 
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            Response.Write("<script>window.close();</script>");
        }
        #region "Save Data"
        public string SaveData(string user_id,string password_c, string password, string Type)
        {
            bs_user myBs = new bs_user(ConfigurationManager.ConnectionStrings["ShowRoomConnectionString"].ToString());
            PccMsg myMsg = new PccMsg();
            myMsg.CreateFirstNode("user_id", user_id);
            myMsg.CreateFirstNode("password_c", password_c);
            myMsg.CreateFirstNode("password", password);
            myMsg.CreateFirstNode("Type", Type);
            string strXML = myMsg.GetXmlStr;
            string strReturn = myBs.DoReturnStr("UPDATEPASS", strXML, "");
            myMsg.LoadXml(strReturn);
            return myMsg.Query("Err");
        }

        #endregion

        #region Ma Hoa Pass
        public static string EncryptMD5(string cleanString)
        {
            Byte[] clearBytes = null;
            clearBytes = new UnicodeEncoding().GetBytes(cleanString);
            Byte[] hashedBytes = ((HashAlgorithm)CryptoConfig.CreateFromName("MD5")).ComputeHash(clearBytes);
            string hashedText = BitConverter.ToString(hashedBytes);
            return hashedText;
        }
        #endregion
    }
}